//
//  XJHttpTool.m
//  网络请求工具类
//
//  Created by RaoBo on 2018/5/3.


//  Copyright © 2018年 关键词. All rights reserved.
//  

#import "XJHttpTool.h"
#import <AFNetworking.h>
#import "XJURLConst.h" // url

#import "XJNet.h"

@implementation XJHttpTool

#pragma mark - 配置 & 全局POST、GET
// 将Dic转为JSON
+ (NSString *)rb_jsonStrFromDic:(NSDictionary *)dic{
    
    if (dic == nil) return nil;
    
    NSError *err;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&err];
    
    if (err) {
        NSLog(@"转JSON失败:%@",err);
        return nil;
    }
    
    NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    XJLog(@"%@",jsonStr);
    
    
    return jsonStr;
}
//json转dic
- (NSDictionary *)rb_dicFromJSON:(NSString *)jsonStr {
    if (jsonStr == nil) {
        return nil;
    }
    
    NSError *err = nil;
    
    NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dic =  [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    
    if (err) {
        return nil;
    }
    return dic;
}

// 保存token
+ (void)rb_saveToken:(NSString *)token {
    
    [[NSUserDefaults standardUserDefaults] setValue:token forKey:@"Authorization"];
}
// 返回token
+ (NSString *)rb_token{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"Authorization"];
}

// 配置AFHTTPSessionManager
+ (AFHTTPSessionManager *)configureAFSessionManager {
    
    AFSecurityPolicy *securityPolicy=[[AFSecurityPolicy alloc]init];
    [securityPolicy setAllowInvalidCertificates:YES];
    AFHTTPSessionManager *sessionManager=[AFHTTPSessionManager  manager];
    [sessionManager setSecurityPolicy:securityPolicy];
    sessionManager.responseSerializer=[AFHTTPResponseSerializer serializer];
    sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    
    //设置超时时间
    [sessionManager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
    sessionManager.requestSerializer.timeoutInterval = 5.0f;
    [sessionManager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
    
    return sessionManager;
}

/**5-12 必须要设置HTTP请求体 才能请求成功
 参考 https://www.jianshu.com/p/f0d187c5a861
 */
+ (void)rb_POSTWithURL:(NSString *)urlStr params:(NSDictionary *)parDic successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {


    // 监测网络状态
    [[XJNet loadNet] netWorkReachabilityState:^(BOOL netState) {
        if (netState) {
            // 先将dic转JSON
            NSString *jsonStr = [self rb_jsonStrFromDic:parDic];
            NSLog(@"请求参数:%@",jsonStr);
            //一 创建请求类,并设置请求头、请求体 就这样写 可用
            NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:urlStr parameters:nil error:nil];
            req.timeoutInterval = 5;
            [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
            
            /**
             备注:1有些接口需要将token放在请求头中传递过去。比如:收藏、
             2. 错误状态码:401 Authorization这个没有填. 没登录。
             */
            if ([self rb_token]) {
                [req setValue:[self rb_token] forHTTPHeaderField:@"Authorization"];
            }
            // 设置请求体: ⚠️❗️
            [req setHTTPBody:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];
            
            // 二 AFURLSessionManager
            AFURLSessionManager *manger = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
            
            //    NSHTTPURLResponse
            
//            [MBProgressHUD showMessage:@"正在加载111111"];

            
            [[manger dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
                
                
                //        NSLog(@"1.响应：%@",response);
                // AFN获取响应头 https://www.jianshu.com/p/a9f09052eaed
                NSHTTPURLResponse *httpRes = (NSHTTPURLResponse *)response;
                NSString *token = httpRes.allHeaderFields[@"Authorization"];
                NSLog(@"token:%@",token);
                
                if (token) { // 登录成功之后会有一个token 保存token 。有的get请求需要设置请求头。
                    [self rb_saveToken:token];
                }
                
                //        NSLog(@"2响应结果:%@",responseObject);
                //        NSLog(@"3.错误:%@",error);
                if (!error) {
//                    XJLog(@"响应体:%@",responseObject);
                    if (success) {
                        
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                            // 为什么要移除多次:这是分装好的get请求 可能被外界调用多次。每调用一次就会showMessage一次。如果show的次数大于hide的次数,bug来了。最后一次hide不掉。
                            //所以干脆来个for循环算了。反正又不会炸。😆
                            for (int i=0; i<3; i++) {
                                [MBProgressHUD hideHUD];
                            }
                            
                        });
                        success(responseObject);
                    }
                }else{
                    if (failure) {
                        for (int i=0; i<3; i++) {
                            [MBProgressHUD hideHUD];
                        }
                        NSLog(@"失败:%@",error);
                        failure(error);
                    }
                    
                    [MBProgressHUD showError:error.localizedDescription];
                }
                // 最后一定要启动,不然方法不走。
            }] resume];
            
        }else {
            [MBProgressHUD showError:@"网络连接已断开"];
        }
    }];
}

// 这个方法不能用 无法设置HTTP请求体
//+ (void)rb_POSTWithURL:(NSString *)urlStr params:(NSDictionary *)parDic successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
//
//    AFHTTPSessionManager *manager = [self configureAFSessionManager];
//
//    [manager POST:urlStr parameters:parDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        NSError *serialErr = nil;
//        // 序列化
//        NSDictionary *respDic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:&serialErr];
//
//        if (success) {
//            success(respDic);
//        }
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//        if (failure) {
//            failure(error);
//        }
//    }];
//}

// 这种方式无法设置请求头
+ (void)rb_GET:(NSString *)urlStr parameters:(NSDictionary *)parDic successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
    AFHTTPSessionManager *manager = [self configureAFSessionManager];
    
//    [MBProgressHUD showMessage:@"正在加载....."];
    [manager GET:urlStr parameters:parDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //避免这样一种情况:外界调用这个方法多次。就会showMessage多次。 但是只hide了一次导致其他的show hide 不掉。避免这种情况。
        for (int i=0; i<3; i++) {
            [MBProgressHUD hideHUD];
        }
        
        
        NSError *serialErr = nil;
        // 序列化
        NSDictionary *respDic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:&serialErr];
        
        if (success) {
            success(respDic);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        [MBProgressHUD hideHUD];
        
        if (failure) {
            failure(error);
        }
    }];
}
// 设置请求头的GET请求
+ (void)rb_GET_haveRequestHeader:(NSString *)urlStr pardic:(NSDictionary *)dic successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
    
//    [MBProgressHUD showMessage:@"正在加载333333"];
    
    NSMutableURLRequest *requestM = [[AFJSONRequestSerializer serializer] requestWithMethod:@"GET" URLString:urlStr parameters:dic error:nil];
    // 设置请求头:token包含在请求头中
    [requestM setValue:[self rb_token] forHTTPHeaderField:@"Authorization"];
    [requestM setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [requestM setValue:@"application/json" forHTTPHeaderField:@"Accept"];

    AFURLSessionManager *manger = [[AFURLSessionManager  alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    [[manger dataTaskWithRequest:requestM completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        
        
        if (!error) {
            if (success) {
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    // 为什么移除两次:这是分装好的get请求 可能对外界调用多次。每调用一次就会showMessage一次。如果show的次数大于hide的次数,bug来了。最后一次hide不掉。
                    //所以干脆俩个for循环算了。反正又不会炸。😆
                    
                    for (int i=0; i<5; i++) {
                        [MBProgressHUD hideHUD];
                    }
                    
                });
                
                success(responseObject);
            }
        } else {
            if (failure) {
                [MBProgressHUD hideHUD];

                failure(error);
            }
        }
    }] resume];
}



#pragma  mark - 具体接口。
+ (void)requestHomeDataWithCoordinate:(NSDictionary *)zuobiaoDic SuccessHandler:(SuccessBlock)succes failureHandler:(FailureBlock)failure
{
    // 请求`url` 参数
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,home];
    
//    NSDictionary *parDic = @{@"lat":@"37.785834",@"lng":@"122.406417"};
    
    [self rb_GET:urlStr parameters:zuobiaoDic successHandler:^(id responseObjc) {
        
        succes(responseObjc);
    } failureHandler:^(NSError *error) {
       
        failure(error);
    }];
}

+ (void)requestHomeSearchWithType:(NSString *)type keyWord:(NSString *)keyword lat:(NSString *)lat lng:(NSString *)lng page:(NSString *)page successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = @"";
    if ([type isEqualToString:@"0"]) { //搜索商品
        url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJHomeSearchGoods];
    }else { //搜索店铺
        url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJHomeSearchShops];
    }
    
    if ([NSString isEmptyString:keyword]) return;

    
    NSString *name = keyword;
    NSDictionary *parDic = NSDictionaryOfVariableBindings(lat,lng,name,page);

    [self rb_GET:url parameters:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

//秒杀
+ (void)requestHomeSecKillWithParDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJHomeSeckill_list];
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

//七牛云token
+ (void)requestQiNiuTokenSuccessH:(SuccessBlock)success fialH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJQiNiuToken];
    [self rb_GET:url parameters:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
+ (void)requestOnlineServicePhoneSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOnline_servicePhone];
    
    [self rb_GET:url parameters:nil successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

#pragma mark -  一 店铺
+ (void)requestShopInfoId:(NSString *)shopId successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
    NSString *shopInfoUrlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJShopInfo];
    
    if (!shopId) {
        NSLog(@"`shopId` 字段不能为空");
        return;
    }
    NSDictionary *parDic = @{@"shop_id":shopId};
    
    [self rb_GET:shopInfoUrlStr parameters:parDic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        failure(error);
    }];
}

+ (void)requestShopCategoryDic:(NSDictionary *)parDic successHandler:(SuccessBlock)success failHandler:(FailureBlock)failure {
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJShopCategoryList];
    [self rb_GET:urlStr parameters:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        failure(error);
    }];
}

/**点击宅配圈获取店铺列表*/
+ (void)requestShopListWithLat:(NSString *)lat lng:(NSString *)lng page:(NSString *)page successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJShopList];
    NSDictionary *dic = @{@"lat":lat,
                          @"lng":lng,
                          @"page":page,
                          @"page_size":@"10"
                          };
    
    [self rb_GET:url parameters:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

#pragma mark - 商品 `goods`
+ (void)requestGoodsInfo:(NSString *)goodsId successHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
    NSString *goodsInfoUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJGoodsInfo];
    if (!goodsId) {
        NSLog(@"goodsId 字段不能为空");
        return;
    }
    NSDictionary *parDic = @{@"goods_id":goodsId};
    
    [self rb_GET:goodsInfoUrl parameters:parDic successHandler:^(id responseObjc) {
        XJLog(@"商品详情：%@",[self rb_jsonStrFromDic:responseObjc]);
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        failure(error);
    }];
}
+ (void)requestShouCangSuccessHandler:(SuccessBlock)succes failureHandler:(FailureBlock)failure{
    NSString *shoucangUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJgoods_collectionList];
    
    [self rb_GET_haveRequestHeader:shoucangUrl pardic:nil successHandler:^(id responseObjc) {
        
        if (succes) {
            succes(responseObjc);
        }
//        NSLog(@"成功:%@",[self rb_jsonStrFromDic:responseObjc]);
    } failureHandler:^(NSError *error) {
        NSLog(@"失败:%@",error);
        
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)requestDeleteShouCangWithIds:(NSString *)ids successH:(SuccessBlock)success failureH:(FailureBlock)fail {
    // 删除收藏的商品
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJDeleteShouCang];
    
    NSDictionary *dic = @{@"ids":ids};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        NSLog(@"成功:%@",responseObjc);
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        NSLog(@"失败:%@",error);
        fail(error);
    }];
}
+ (void)requestAddShouCangWithGoods_id:(NSString *)goodId successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddShouCang];
    
    if ([NSString isEmptyString:goodId]) {
        XJLog(@"商品编号为空 无法操作");
        return;
    }
    
    NSDictionary *dic = @{@"goods_id":goodId};
    
    [self rb_POSTWithURL:urlStr params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
/**取消收藏商品*/
+ (void)requestCancelShouCangGoodsWithGoodsId:(NSString *)goods_id successH:(SuccessBlock)success fail:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCancelShouCangGoods];
    
    if([NSString isEmptyString:goods_id]) return;
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(goods_id);
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestRecomendGoodsWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJRecommendGoods];
    
    [self rb_GET:url parameters:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
+ (void)requestGoodsAllEvaluateWithGoodsId:(NSString *)goods_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJGoodsAllEvaluate];

    NSNumber *page = @(1);
    NSNumber *page_size = @(10); //1页返回多少条数据
    NSDictionary *parDic = NSDictionaryOfVariableBindings(page,page_size,goods_id);
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - 登录注册
+ (void)requestLoginWithPhoneNum:(NSString *)phoneNum password:(NSString *)pwd successHandler:(SuccessBlock)succes failureHandler:(FailureBlock)failure {
    NSString *loginURLStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJLoginPwd];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:phoneNum forKey:@"customer_name"];
    [dic setValue:pwd forKey:@"password"];
    
    NSLog(@"登录参数:%@",dic);
    [self rb_POSTWithURL:loginURLStr params:dic successHandler:^(id responseObjc) {
        
        succes(responseObjc);
    } failureHandler:^(NSError *error) {
        
        failure(error);
    }];
}
// 注册
+ (void)requestRegisterParameter:(NSDictionary *)parDic successHandler:(SuccessBlock)succes failureHandler:(FailureBlock)fail {

    
    NSString *registUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJRegist];
    
    [self rb_POSTWithURL:registUrl params:parDic successHandler:^(id responseObjc) {
        succes(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
//
//    NSString *jsonStr = [self rb_jsonStrFromDic:parDic];
//    // 一:创建请求类设置请求头请求体
//    NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:registUrl parameters:nil error:nil];
//    req.timeoutInterval = 5.0;
//    // 设置请求头
//    [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//    [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//
//    // 设置请求体
//    [req setHTTPBody:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];
//
//    // 二:AFURLSessionManager
//    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
//
//    // 三:
//    [[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//        if (error) {
//            if (fail) {
//
//                [JRToast showWithText:[NSString stringWithFormat:@"%@",error.description]];
//                fail(error);
//            }
//        }else {
//            if (succes) {
//                succes(responseObject);
//            }
//        }
//    }] resume];
    
//    // 图片
//    UIImage *tmpImg = [UIImage imageNamed:@"github.png"];
//    NSData *data = UIImageJPEGRepresentation(tmpImg, 0.7);
//    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
//    fmt.dateFormat = @"yyyyMMddHHmmss";
//    NSString *timeStr = [fmt stringFromDate:[NSDate date]];
//    NSString *fileName = [NSString stringWithFormat:@"%@.jpg",timeStr];
//
//
//    // 三:发送请求：注册的同时还要上传图片
//    [manager uploadTaskWithRequest:req fromData:data  progress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//        NSLog(@"");
//    }];
}
+ (void)requestSendCodeWithPhone:(NSString *)phone type:(NSString *)type successH:(SuccessBlock)success failureH:(FailureBlock)fail {
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJSend_code];
    NSDictionary *dic = @{@"phone":phone,
                          @"type":type,
                          };
    
    // POST请求
    [self rb_POSTWithURL:urlStr params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


+ (void)requestVerifyCodeWithPhone:(NSString *)phone code:(NSString *)code type:(NSString *)type successH:(SuccessBlock)success failureH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJVerify_code];
    NSDictionary *dic = @{@"phone":phone,
                          @"verify_code":code,
                          @"type":type
                          };
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestRegisterWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failureH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJRegist];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

// 忘记密码
+ (void)requestForgetPwdWithDic:(NSDictionary *)dic succesH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJForgetPwd];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCustomDetailSuccesH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerDetail];
    
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCustomAccountFinanceLsitWithFinceType:(NSString *)finance_type successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerAccountFinanceList];
    
    NSDictionary *dic = nil;
    if (![NSString isEmptyString:finance_type]) {
        dic = NSDictionaryOfVariableBindings(finance_type);
    }
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

//+ (void)requestCustomAccountFinanceLsitSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
//    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerAccountFinanceList];
//
//    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
//        success(responseObjc);
//    } failureHandler:^(NSError *error) {
//        fail(error);
//    }];
//}

+ (void)requestCustomAccountAccountListSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString * url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerAccountAccountList];
    
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCustomAccountAddAccountWithParDic:(NSDictionary *)parDic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString  *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerAccountAddAccount];
    
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestCustomAccountTiXianWithParDic:(NSDictionary *)parDic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerAccountTiXian];
    
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - 分类
/**获取分类数据5-10*/
+ (void)requestCategoryDataSuccessHandler:(SuccessBlock)success failureHandler:(FailureBlock)failure {
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCategoryList];
    
    [self rb_GET:urlStr parameters:nil successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        failure(error);
    }];
}

+ (void)requestCategorySecondPageDataWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCategorySecondPageData];

    [self rb_GET:url parameters:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

#pragma mark - ======五 购物车 customer======
+ (void)requestAddCartDic:(NSDictionary *)dic successH:(SuccessBlock)success failureH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddCart];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestCartListSuccessH:(SuccessBlock)success failureH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCartList];
    
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestDeleteCartWithIdsStr:(NSString *)idsStr successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJDeleteCart];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:idsStr forKey:@"ids"];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
        
        XJLog(@"%@",responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
        XJLog(@"%@",error);
    }];
}

#pragma mark - ======六 收货地址 customer_address=======
+ (void)requestAddressListSuccessH:(SuccessBlock)success failureH:(FailureBlock)fail {
    NSString *addressListUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddressList];
    
    [self rb_GET_haveRequestHeader:addressListUrl pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestAddNewAddressWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddAddressInsert];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestDeleteAddressWithDistrictId:(NSString *)districtId successH:(SuccessBlock)success failH:(FailureBlock)fail {
   
    if ([NSString isEmptyString:districtId]) {
        XJLog(@"地址id为空，操作无效");
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddressDelete];
    NSDictionary *dic = @{@"districtId":districtId};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestDefaultAddressWithDistrictId:(NSString *)districtId successH:(SuccessBlock)success fialH:(FailureBlock)fail {
    if ([NSString isEmptyString:districtId]) {
        XJLog(@"地址id为空，操作无效");
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJAddressDefault];
    NSDictionary *dic = @{@"id":districtId};

    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

#pragma mark - =======七 个人信息  customer/edit =========
+ (void)requestEditPersonMessageWithName:(NSString *)nickname sex:(NSString *)sex avator:(NSString *)avator successH:(SuccessBlock)succes failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomerEdit];
    //如果所传的字段为空 就忽略该字段
    
    NSMutableDictionary *dicM = [NSMutableDictionary dictionary];
    if (![NSString isEmptyString:nickname]) {
        [dicM setValue:nickname forKey:@"nickname"];
    }
    if (![NSString isEmptyString:[NSString stringWithFormat:@"%@",sex]]) {
        [dicM setValue:sex forKey:@"sex"];
    }
    if (![NSString isEmptyString:avator]) {
        [dicM setValue:avator forKey:@"avatar"];
    }
    
    //custom_id;
    NSString *customId =    [XJUserModel xj_customId];
    if (![NSString isEmptyString:customId]) {
        [dicM setValue:customId forKey:@"customerId"];
    }
    
    [self rb_POSTWithURL:url params:dicM successHandler:^(id responseObjc) {
        succes(responseObjc);
        
        [self rb_jsonStrFromDic:responseObjc];
        
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestModifyLoginPwd:(NSString *)pwd successH:(SuccessBlock)succe failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJModifyLoginPwd];
    
    NSDictionary *dic = @{@"password":pwd};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        succe(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestModifyPayPwd:(NSString *)pwd successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJModifyPayPwd];
    
    NSDictionary *dic = @{@"password":pwd};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - ======== 八 订单相关 order/balance ==========
/**GET order/balance 点击立即购买 获取数据*/
+ (void)requestBuyNowWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderBalance];
    XJLog(@"%@",url);
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
        [self rb_jsonStrFromDic:responseObjc];
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

/**"确认订单"页面点击立即下单按钮*/
+ (void)requestOrderGenerateOrderWithDic:(NSDictionary *)dic successH:(SuccessBlock)succes failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderGenerateOrder];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        succes(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

/**我的页面 获取待付款 上面的角标*/
+ (void)requestOrderOrderCountSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *orderCountUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderOrderCount];
    
    [self rb_GET_haveRequestHeader:orderCountUrl pardic:nil successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}
/**获取订单列表(全部、待付款、待收货、...) 6-14*/
+ (void)requestOrderOrderListsWithType:(NSString *)type page:(NSString *)page successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *orderListsURL = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderOrderLists];

    if ([NSString isEmptyString:page]) {
        page = @"1";
    }
    
    NSDictionary *parDic = @{@"order_type":type,
                             @"page":page,
                             @"page_size":@"10"
                             };
    
    [self rb_GET_haveRequestHeader:orderListsURL pardic:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestOrderCancelOrderWithOrderNum:(NSString *)order_sn successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *cancelOrderUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderCancelOrder];
    
    NSDictionary *parDic = @{@"order_sn":order_sn};
    
    [self rb_POSTWithURL:cancelOrderUrl params:parDic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestOrderDeleteOrderWithOrderSN:(NSString *)order_sn successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *deleteOrderUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderDeleteOrder];
    
    NSDictionary *dic = @{@"order_sn":order_sn};
    
    [self rb_POSTWithURL:deleteOrderUrl params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestOrderReceiveWithOrderSN:(NSString *)order_sn successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *orderReceiveUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderReceive];
    
    NSDictionary *dic = @{@"order_sn":order_sn};
    
    [self rb_POSTWithURL:orderReceiveUrl params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestOrderDetailWithOrderSN:(NSString *)orderSn successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderDetail];
    
    NSDictionary *dic = @{@"order_sn":orderSn};
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - ========九 社区  community ============
/**点击首页--标签---->社区在线---->跳转的接口*/
+ (void)requestCommunityNearestWithLng:(NSString *)lng lat:(NSString *)lat successH:(SuccessBlock)success failH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityNearest];
    
    NSDictionary *dic = @{@"lng":lng,
                          @"lat":lat};
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestCommunityServeCategorySuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    // get
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityServiceCategory];
    
//    [self rb_GET:url parameters:nil successHandler:^(id responseObjc) {
//        success(responseObjc);
//    } failureHandler:^(NSError *error) {
//        fail(error);
//    }];
    // 一定要加请求头,不然 401
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunitySubmitServeDic:(NSDictionary *)dic successH:(SuccessBlock)succes failH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityServiceCommit];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        succes(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunityServeListWithCommunityId:(NSString *)community_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString * url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityServiceList];
    
    NSDictionary *dic = @{@"community_id":community_id};
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunityServiceDetailWithServiceId:(NSString *)serviceId successH:(SuccessBlock)success fialH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityServiceInfo];
    
    NSDictionary *dic = @{@"service_id":serviceId};
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunityServiceCancelWithURLPath:(NSString *)path Service_id:(NSString *)service_id successH:(SuccessBlock)success failH:(FailureBlock)fail{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,path];
    
    NSDictionary *dic = @{@"service_id":service_id};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunityToSearchWithLat:(NSString *)lat lng:(NSString *)lng customId:(NSString *)customer_id successH:(SuccessBlock)success fialH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommuntiyToSearch];
    
    NSDictionary *dic = @{@"lat":lat,
                          @"lng":lng,
                          @"customer_id":customer_id
                          };
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunityEnterCommunity_id:(NSString *)community_id customer_id:(NSString *)customer_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityEnter];
    
    NSDictionary *dic = @{@"community_id":community_id,
                          @"customer_id":customer_id
                          };
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestCommunitySearchWithLng:(NSString *)lng lat:(NSString *)lat name:(NSString *)name successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunitySearch];
    
    NSDictionary *dic = @{@"lng":lng,
                          @"lat":lat,
                          @"name":name
                          };
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

//社区认证
+ (void)requestCommunityIdentityWithParDic:(NSDictionary *)parDic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityIdentity];
    
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

/**是否通过了社区认证 返回结果 status 1为正在审核，2审核通过，3为审核失败*/
+ (void)requestCommunityIdentityIsIdentityWithCmtId:(NSString *)community_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityIdentityIsIdentity];
    
    if ([NSString isEmptyString:community_id]) {
        XJLog(@"community_id 为空操作无效");
        return;
    }
    
    NSDictionary *parDic = @{@"community_id":community_id};
    
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
//7-16 社区认证详情
+ (void)requestCommunityIdentityDetailWithCommunityID:(NSString *)community_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityIdentityDetail];
    
    if ([NSString isEmptyString:community_id]) {
        XJLog(@"社区id为空操作无效:%@",community_id);
        return;
    }
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(community_id);
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
/**社区认证列表*/
+ (void)requestCommunityIdentityListSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCommunityIdentityList];
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - ========十 帖子  invitation(请帖、邀请) ============
/**首页---本地旅游---搜索城市帖子*/
+ (void)requestInvitationFindCity:(NSString *)city keyword:(NSString *)title successH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationCityFind];
    NSDictionary *dic = @{@"title":title,@"city":city};
    
    [self rb_GET:url parameters:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestInvitationCityPageCity:(NSString *)cityStr successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationCityPage];
    
    NSString *city = cityStr;
    NSNumber *category_id = @(1);
    NSDictionary *parDic = NSDictionaryOfVariableBindings(city,category_id);
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {

        fail(error);
    }];
}


// 帖子列表
+ (void)requestInvitationListWithDic:(NSDictionary *)dic succesH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationList];
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestInvitationDetailInfoWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationInfo];
    
    // 有的接口需要设置请求头.(token) 不然会报401未授权。
    // 不能用带请求头的方法,直接返回500
    [self rb_GET:url parameters:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

/**7-9 搜索有名堂帖子*/
+ (void)requestInvitationYMTSearchTopicsWithTitle:(NSString *)title successH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationYMTTopicsSearch];
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(title);
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {

        success(responseObjc);
    } failureHandler:^(NSError *error) {

        fail(error);
    }];
}

+ (void)requestInvitationCommentWithDic:(NSDictionary *)dic succesH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationComment];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


+ (void)requestInvitationDeleteCommentWithCommentId:(NSString *)commentId successH:(SuccessBlock)success failH:(FailureBlock)fail {

    NSString * url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationDeleteComment];
    
    NSDictionary *dic = @{@"comment_id":commentId};
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        
        success(responseObjc);

    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestInvitationSkipToJuBaoPageSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationSkipToJuBaoPage];
    
    [self rb_GET:url parameters:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestInvitationJuBaoTieZiWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationJuBao];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


#pragma mark - ========十 -2 帖子收藏  invitationCollection  ============
+ (void)requestInvitationCollectionListSuccessH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationCollectionList];
    
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}

+ (void)requestInvitationCollectionDeleteWithIds:(NSString *)ids successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationCollectionDelete];
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(ids);
    
    XJLog(@"删除收藏的帖子请求参数:%@",parDic);
    
    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}
+ (void)requestInvitationColllectionCollectionWithInvitation_id:(NSString *)invitation_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationCollectionCollection];
    
    NSDictionary *parDic = NSDictionaryOfVariableBindings(invitation_id);

    [self rb_POSTWithURL:url params:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

#pragma mark - ========十一 支付  pay ============
+ (void)requestPayPrepayWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *prepayURL = [NSString stringWithFormat:@"%@%@",XJMainURL,XJPayPrePay];
    
    [self rb_POSTWithURL:prepayURL params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestPayWithDic:(NSDictionary *)payDic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *payUrl = [NSString stringWithFormat:@"%@%@",XJMainURL,XJPay];
    
    [self rb_POSTWithURL:payUrl params:payDic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}


#pragma mark - ========十二 售后相关  refund ============
+ (void)requestOrderOrderPageWithOrderGoodsId:(NSString *)order_goods_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderOrderPage];
    
    NSDictionary *dic = @{@"order_goods_id":order_goods_id};

    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

/**申请售后*/
+ (void)requestRefundCommitRefundWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJRefoundRefoundCommit];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestOrderCommentWithDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJOrderComment];
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

+ (void)requestRefoundListSuccessH:(SuccessBlock)success failH:(FailureBlock)fail{
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJRefoundList];
    
    NSDictionary *dic = @{@"page":@"1",
                          @"page_size":@"10"
                          };
    
    [self rb_GET_haveRequestHeader:url pardic:dic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        
        fail(error);
    }];
}



#pragma mark - ========十三 首页先关 ============
//首页tag---超市商场--大类
+ (void)requestHomeTagSupermarketWithGoodsCategoryId:(NSString *)goods_cty_id successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJHomeGoodsCategoryList];
    
    NSDictionary *parDic = @{@"goods_category_id":goods_cty_id};
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
       
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}



#pragma mark - ========== 十四 消息管理 ==========
+ (void)requestCustomMessageListWithMsgType:(NSString *)msgType page:(NSString *)page successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomMessageList];
    
    NSDictionary *parDic = @{@"page":page,
                             @"page_size":@"10",
                             @"message_type":msgType,
                             @"is_update":@"0"
                             };
    
    [XJHttpTool rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}




+ (void)requestInvitationReplyMeWithPage:(NSString *)page successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJInvitationReplyMe];
    
    NSDictionary *parDic = @{@"page":page,
                             @"page_size":@"20"
                             };
    
    [self rb_GET_haveRequestHeader:url pardic:parDic successHandler:^(id responseObjc) {
        
        success(responseObjc);
        
    } failureHandler:^(NSError *error) {
    
        fail(error);
    }];
}

#pragma mark - 十五  实名认证
/**检查是否进行了实名认证*/
+ (void)requestCustomIsIdentitySuccesH:(SuccessBlock)success failH:(FailureBlock)fail {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomIdentityIsIdentity];
    
    [self rb_GET_haveRequestHeader:url pardic:nil successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}


/**进行实名认证*/
+ (void)requetCustomIdentityWithParDic:(NSDictionary *)dic successH:(SuccessBlock)success failH:(FailureBlock)fail {
    NSString *url = [NSString stringWithFormat:@"%@%@",XJMainURL,XJCustomIdentityIdentity];
    
    
    [self rb_POSTWithURL:url params:dic successHandler:^(id responseObjc) {
        success(responseObjc);
    } failureHandler:^(NSError *error) {
        fail(error);
    }];
}

@end
